package com.stylefeng.guns.modular.system.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import com.stylefeng.guns.modular.system.dao.ArtificerBusinessMapper;
import com.stylefeng.guns.modular.system.model.ArtificerBusiness;
import com.stylefeng.guns.modular.system.service.IArtificerBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 技师经营的项目 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2019-09-09
 */
@Service
@Slf4j
public class ArtificerBusinessServiceImpl extends ServiceImpl<ArtificerBusinessMapper, ArtificerBusiness> implements IArtificerBusinessService {

    @Resource
    private ArtificerBusinessMapper artificerBusinessMapper;

    @Override
    public ResponseResultDTO searchByArtificerId(Integer id) {
        ResponseResultDTO responseResultDTO = new ResponseResultDTO();
        if (id == null || "".equals(id)) {
            responseResultDTO.setStatus("-1");
            responseResultDTO.setMsg("PARAM-NULL");
            return responseResultDTO;
        }
        try {
            Map<String, Object> param = new HashMap<>();
            param.put("artificerId", id);
            List<ArtificerBusiness> list = artificerBusinessMapper.selectByMap(param);
            responseResultDTO.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("系统异常：{}", e.getMessage());
            responseResultDTO.setStatus("-1");
            responseResultDTO.setMsg("系统异常");
        }
        return responseResultDTO;
    }

    @Override
    public ResponseResultDTO getAllBusiness(Integer id) {
        ResponseResultDTO responseResultDTO = new ResponseResultDTO();
        try {
            List<Map> list = artificerBusinessMapper.selectAllBusiness(id);
            responseResultDTO.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("查询所有的项目异常：{}", e);
            responseResultDTO.setStatus("-1");
            responseResultDTO.setMsg("查询所有的项目异常");
        }
        return responseResultDTO;
    }

    @Override
    public ResponseResultDTO getOneBusiness(Integer id) {
        ResponseResultDTO responseResultDTO = new ResponseResultDTO();
        try {
            List<Map> list = artificerBusinessMapper.selectOneBusiness(id);
            responseResultDTO.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("查询单个项目异常：{}", e);
            responseResultDTO.setStatus("-1");
            responseResultDTO.setMsg("查询单个项目异常");
        }
        return responseResultDTO;
    }
}
